import { loginAPI } from '@/api/user'

export default {
  namespaced: true,
  state: {
    token: null,
    ueerInfo: {}
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    removeToken(state) {
      state.token = null
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    removeUserInfo(state) {
      state.userInfo = {}
    }
  },
  actions: {
    async loginAction({ commit }, val) {
      const { data } = await loginAPI(val)
      // console.log(data)
      if (data.success) {
        commit('setToken', data.token)
        commit('setUserInfo', data)
      }
      return data
    }
  }
}
